<?php

class ProductController extends Zend_Controller_Action{

    public function init(){
		 $this->auth_instance = Zend_Auth::getInstance();
    }

    public function indexAction(){
   		echo 'PRODUCT ID --> ' . $this->_getParam('productID');
    }

   
    public function laptopsAction(){
    	$productMapper = new Application_Model_ProductMapper();
    	$categMapper = new Application_Model_CategoryMapper();
    	$products = $productMapper->fetchAll();
    	
		for($i=0; $i< sizeof($products); $i++) {

		  /*echo 'Categoria este: '. $products[$i]->getId_category(). '<br />';*/
			if ( $products[$i]->getId_category() == 1){
				echo '<div id="'. $products[$i]->getId().'" class="product">';
				echo '<div>'. $products[$i]->getName().'</div>';
	            echo '<hr width="100%" align="left" />';
				echo '<a href="/product/index/productID/'. $products[$i]->getId().'"><img width="140" height="110" src='. $products[$i]->getPicture_location() .' /></a>';		
				echo '<br />'. '<br />';
			   	echo '<a href="/product/index/productID/'. $products[$i]->getId(). '">detalii</a>';
				echo '<br />'. '<br />';
				echo '<div>'. 'Pret: '. $products[$i]->getPrice(). ' Ron' .'</div>';
				echo '<br />'. '<br />';
				
			if ( $products[$i]->getId() == 1){
				
					$host="localhost";
					$username="root";
					$password="";
					$db_name="estore";
					$tbl_name="specification ";
				
				
					$con=mysqli_connect($host, $username, $password, $db_name);
				
					if (mysqli_connect_errno($con))
					{
						echo "Failed to connect to MYSQL :". mysqli_connect_errno();
					}
					$result= mysqli_query($con, "SELECT * FROM specification WHERE id_product='1' ");
					while ($row = mysqli_fetch_array($result))
					{
						echo '<div >'.$row['spec_name']. " - " .$row['spec_value']. '</div>';
					}	
			}	
					
			if ( $products[$i]->getId() == 2){
					
					$host="localhost";
					$username="root";
					$password="";
					$db_name="estore";
					$tbl_name="specification ";
						
				
					$con=mysqli_connect($host, $username, $password, $db_name);
						
					if (mysqli_connect_errno($con))
					{
						echo "Failed to connect to MYSQL :". mysqli_connect_errno();		
					}
					$result= mysqli_query($con, "SELECT * FROM specification WHERE id_product='2'");
					while ($row = mysqli_fetch_array($result))
					{
						echo '<div>'.$row['spec_name']." - " .$row['spec_value']. '</div>';		
					}		
			}
				echo '<br />'. '<br />';
				echo '<br />'. '<br />';		
				echo '</div>';
			}
		}
    }
   
    public function monitorsAction(){
	    $productMapper = new Application_Model_ProductMapper();
    	$categMapper = new Application_Model_CategoryMapper();
    	$products = $productMapper->fetchAll();
    	
    	for($i=0; $i< sizeof($products); $i++) {

		  /*echo 'Categoria este: '. $products[$i]->getId_category(). '<br />';*/
			if ( $products[$i]->getId_category() == 2){
				echo '<div id="'. $products[$i]->getId().'" class="product">';
				echo '<div>'. $products[$i]->getName().'</div>';
				echo '<hr width="100%" align="left" />';
				echo '<a  href="/product/' . $products[$i]->getId().'"><img width="140" height="110" src=' . $products[$i]->getPicture_location() .' /></a>';
			    echo '<br />'. '<br />';
				echo '<a href="/product/'. $products[$i]->getId().'">detalii</a>';
				echo '<br />'. '<br />';
				echo '<div>'. 'Pret: ' . $products[$i]->getPrice(). ' Ron' .'</div>';
				echo '<br />'. '<br />';
				echo '</div>';
				
				
			}	
    	}
    }  
    
    public function componentsAction(){
    	$productMapper = new Application_Model_ProductMapper();
    	$categMapper = new Application_Model_CategoryMapper();
    	$products = $productMapper->fetchAll();
    	 
    	for($i=0; $i< sizeof($products); $i++) {
    
    		/*echo 'Categoria este: '. $products[$i]->getId_category(). '<br />';*/
    		if ( $products[$i]->getId_category() == 3){
    			echo '<div id="'. $products[$i]->getId().'" class="product">';
    			echo '<div>'. $products[$i]->getName().'</div>';
    			echo '<hr width="100%" align="left" />';
    			echo '<a  href="/product/' . $products[$i]->getId().'"><img width="140" height="110" src=' . $products[$i]->getPicture_location() .' /></a>';
    			echo '<br />'. '<br />';
    			echo '<a href="/product/'. $products[$i]->getId().'">detalii</a>';
    			echo '<br />'. '<br />';
    			echo '<div>'. 'Pret: ' . $products[$i]->getPrice(). ' Ron' .'</div>';
    			echo '<br />'. '<br />';
    			echo '</div>';
    
    				
    		}
    	}
    }

    public function computersAction(){
		$productMapper = new Application_Model_ProductMapper();
    	$categMapper = new Application_Model_CategoryMapper();
    	$products = $productMapper->fetchAll();
    	
		for($i=0; $i< sizeof($products); $i++) {

		  /*echo 'Categoria este: '. $products[$i]->getId_category(). '<br />';*/
			if ( $products[$i]->getId_category() == 4){
				echo '<div id="'. $products[$i]->getId().'" class="product">';
				echo '<div>'. $products[$i]->getName().'</div>';
				echo '<hr width="50%" align="left" />';
				echo '<a  href="/product/ ' . $products[$i]->getId().'"><img width="140" height="110" src=' . $products[$i]->getPicture_location() .' /></a>';
				echo '<br />'. '<br />';
				echo '<a href="/product/'. $products[$i]->getId().'">detalii</a>';
				echo '<br />'. '<br />';
				echo '<div>'. 'Pret: ' . $products[$i]->getPrice(). ' Ron' .'</div>';
				echo '<br />'. '<br />';
				echo '<div>';
			}
		 }
    }

    public function serversAction(){
		$productMapper = new Application_Model_ProductMapper();
    	$categMapper = new Application_Model_CategoryMapper();
    	$products = $productMapper->fetchAll();

		for($i=0; $i< sizeof($products); $i++) {

		  /*echo 'Categoria este: '. $products[$i]->getId_category(). '<br />';*/
			if ( $products[$i]->getId_category() == 5){
				echo '<div id="'. $products[$i]->getId().'" class="product">';
				echo '<div>'. $products[$i]->getName().'</div>';
				echo '<hr width="70%" align="left" />';
				echo '<a  href="/product/ ' . $products[$i]->getId().'"><img width="140" height="110" src=' . $products[$i]->getPicture_location() .' /></a>';
				echo '<br />'. '<br />';
				echo '<a href="/product/'. $products[$i]->getId().'">detalii</a>';
				echo '<br />'. '<br />';
				echo '<div>'. 'Pret: ' . $products[$i]->getPrice(). ' Ron' .'</div>';
				echo '<br />'. '<br />';
				echo '<div>';
			}
		 }
    }

    public function photoAction(){
		$productMapper = new Application_Model_ProductMapper();
    	$categMapper = new Application_Model_CategoryMapper();
    	$products = $productMapper->fetchAll();

		for($i=0; $i< sizeof($products); $i++) {

		  /*echo 'Categoria este: '. $products[$i]->getId_category(). '<br />';*/
			if ( $products[$i]->getId_category() == 6){
				echo '<div id="'. $products[$i]->getId().'" class="product">';
				echo '<div>'. $products[$i]->getName().'</div>';
				echo '<hr width="60%" align="left" />';
				echo '<a  href="/product/ ' . $products[$i]->getId().'"><img width="140" height="110" src=' . $products[$i]->getPicture_location() .' /></a>';
				echo '<br />'. '<br />';
				echo '<a href="/product/'. $products[$i]->getId().'">detalii</a>';
				echo '<br />'. '<br />';
				echo '<div>'. 'Pret: ' . $products[$i]->getPrice(). ' Ron' .'</div>';
				echo '<br />'. '<br />';
				echo '<div>';
			}
		 }

    }

    public function printerAction(){
		$productMapper = new Application_Model_ProductMapper();
    	$categMapper = new Application_Model_CategoryMapper();
    	$products = $productMapper->fetchAll();

		for($i=0; $i< sizeof($products); $i++) {

		  /*echo 'Categoria este: '. $products[$i]->getId_category(). '<br />';*/
			if ( $products[$i]->getId_category() == 7){
				echo '<div id="'. $products[$i]->getId().'" class="product">';
				echo '<div>'. $products[$i]->getName().'</div>';
				echo '<hr width="100%" align="left" />';
				echo '<a  href="/product/ ' . $products[$i]->getId().'"><img width="140" height="110" src=' . $products[$i]->getPicture_location() .' /></a>';
				echo '<br />'. '<br />';
				echo '<a href="/product/'. $products[$i]->getId().'">detalii</a>';
				echo '<br />' . '<br />';
				echo '<div>'. 'Pret: ' . $products[$i]->getPrice(). ' Ron' .'</div>';
				echo '<br />' . '<br />';
				echo '</div>';
			}
		 }

    }

    public function softwareAction(){
		$productMapper = new Application_Model_ProductMapper();
    	$categMapper = new Application_Model_CategoryMapper();
    	$products = $productMapper->fetchAll();

		for($i=0; $i< sizeof($products); $i++) {

		  /*echo 'Categoria este: '. $products[$i]->getId_category(). '<br />';*/
			if ( $products[$i]->getId_category() == 8){
				echo '<div id="'. $products[$i]->getId().'" class="product">';
				echo '<div>'. $products[$i]->getName().'</div>';
				echo '<hr width="100%" align="left" />';
				echo '<a  href="/product/ ' . $products[$i]->getId().'"><img width="140" height="110" src=' . $products[$i]->getPicture_location() .' /></a>';
			   echo '<br />'. '<br />';
				echo '<a href="/product/'. $products[$i]->getId().'">detalii</a>';
				echo '<br />' . '<br />';
				echo '<div>'. 'Pret: ' . $products[$i]->getPrice(). ' Ron' .'</div>';
				echo '<br />' . '<br />';
				echo '</div>';
			}
		 }

    }

    public function phonesAction(){
		$productMapper = new Application_Model_ProductMapper();
    	$categMapper = new Application_Model_CategoryMapper();
    	$products = $productMapper->fetchAll();

		for($i=0; $i< sizeof($products); $i++) {

		  /*echo 'Categoria este: '. $products[$i]->getId_category(). '<br />';*/
			if ( $products[$i]->getId_category() == 9){
				echo '<div id="'. $products[$i]->getId().'" class="product">';
				echo '<div>'. $products[$i]->getName().'</div>';
				echo '<hr width="100%" align="left" />';
				echo '<a  href="/product/ ' . $products[$i]->getId().'"><img width="70" height="110" src=' . $products[$i]->getPicture_location() .' /></a>';
		        echo '<br />'. '<br />';
				echo '<a href="/product/'. $products[$i]->getId().'">detalii</a>';
				echo '<br />' . '<br />';
				echo '<div>'. 'Pret: ' . $products[$i]->getPrice(). ' Ron' .'</div>';
				echo '<br />' . '<br />';
				echo '</div>';
				
			}
		 }
    }


}